/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (the
 *  "License"); you may not use this file except in compliance
 *  with the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */
package org.apache.directory.mavibot.btree;

import java.util.concurrent.atomic.AtomicLong;

/**
 * A class used to store the cache's statistics
 * 
 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
 *
 */
public class CacheStatistics implements MyCacheStatistics
{
	private AtomicLong nbTotalAccess;
	private AtomicLong nbReadAccess;
	private AtomicLong nbHits;
	private AtomicLong nbMiss;
	private AtomicLong nbPut;
	private AtomicLong size;
	
	/**
	 * initialize the CacheStatistics object  with the size of the cache
	 * @param size
	 */
	public CacheStatistics( int size )
	{
		nbTotalAccess=new AtomicLong();
		nbReadAccess=new AtomicLong();
		nbHits=new AtomicLong();
		nbMiss=new AtomicLong();
		nbPut=new AtomicLong();
		this.size=new AtomicLong();
	}
	
	/**
	 * update all the statistics of the cache
	 * @param Hit
	 * @param put
	 */
	public void UpdateStatistics( boolean Hit, boolean put )
	{
		nbTotalAccess.incrementAndGet();
		if( put )
		{
			nbPut.incrementAndGet();
		}
		else
		{
			nbReadAccess.incrementAndGet();
			if( Hit )
			{
				nbHits.incrementAndGet();
			}
			else
			{
				nbMiss.incrementAndGet();
			}
		}
	}

	public long getNbReadAccess() 
	{
		return nbReadAccess.get();
	}

	public void setNbReadAccess( long nbAccess ) 
	{
		this.nbReadAccess.set(nbAccess);
	}

	public long getNbHits() 
	{
		return nbHits.get();
	}

	public void setNbHits( long nbHits ) 
	{
		this.nbHits.set(nbHits);
	}

	public long getNbMiss() 
	{
		return nbMiss.get();
	}

	public void setNbMiss( long nbMiss ) 
	{
		this.nbMiss.set(nbMiss);
	}

	public long getSize() 
	{
		return size.get();
	}

	public void setSize( long size ) 
	{
		this.size.set(size);
	}
	
	public long getNbPut() {
		return nbPut.get();
	}

	public void setNbPut( long nbPut ) {
		this.nbPut.set(nbPut);
	}
	
	public long getNbTotalAccess() {
		return nbTotalAccess.get();
	}

	public void setNbTotalAccess( long nbTotalAccess ) {
		this.nbTotalAccess.set(nbTotalAccess);
	}

}
